#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
#include<string>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long LL;
const int N = 110;
int arr[N][N];
int n;
struct S
{
	int x, y;
	int sum;
}s[N*N];
int cmp(S a, S b)
{
	return a.sum < b.sum;
}
int main()
{
	int t;
	cin >> t;
	while (t--) {
		cin >> n;
		int k = 0;
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				cin >> arr[i][j];
				s[k].sum = arr[i][j];
				s[k].x = i;
				s[k++].y = j;
			}
		}
		sort(s, s + n, cmp);
	}
	return 0;
}

//11 949